{
 "cells": [
  {
   "cell_type": "raw",
   "id": "1a4247fd",
   "metadata": {},
   "source": [
    "异常值检测：\n",
    "    箱线图\n",
    "    3σ原则\n",
    "异常值处理：\n",
    "   删除\n",
    "   替换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "15a8130c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5843c884",
   "metadata": {},
   "source": [
    "1.读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "08014e52",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>PassengerId</th>\n",
       "      <th>Survived</th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Name</th>\n",
       "      <th>Sex</th>\n",
       "      <th>Age</th>\n",
       "      <th>SibSp</th>\n",
       "      <th>Parch</th>\n",
       "      <th>Ticket</th>\n",
       "      <th>Fare</th>\n",
       "      <th>Embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Braund, Mr. Owen Harris</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>A/5 21171</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>PC 17599</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>Heikkinen, Miss. Laina</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>STON/O2. 3101282</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>113803</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Allen, Mr. William Henry</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>373450</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0  PassengerId  Survived  Pclass  \\\n",
       "0           0            1         0       3   \n",
       "1           1            2         1       1   \n",
       "2           2            3         1       3   \n",
       "3           3            4         1       1   \n",
       "4           4            5         0       3   \n",
       "\n",
       "                                                Name     Sex   Age  SibSp  \\\n",
       "0                            Braund, Mr. Owen Harris    male  22.0      1   \n",
       "1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1   \n",
       "2                             Heikkinen, Miss. Laina  female  26.0      0   \n",
       "3       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1   \n",
       "4                           Allen, Mr. William Henry    male  35.0      0   \n",
       "\n",
       "   Parch            Ticket     Fare Embarked  \n",
       "0      0         A/5 21171   7.2500        S  \n",
       "1      0          PC 17599  71.2833        C  \n",
       "2      0  STON/O2. 3101282   7.9250        S  \n",
       "3      0            113803  53.1000        S  \n",
       "4      0            373450   8.0500        S  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('./titanic_trains_nonull.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4a7237f",
   "metadata": {},
   "source": [
    "2.异常值处理"
   ]
  },
  {
   "cell_type": "raw",
   "id": "f71b9a50",
   "metadata": {},
   "source": [
    "注意点：\n",
    "    1.考试中出现概率较低。\n",
    "    2.题目一般会说请对哪些列进行异常值处理，如果没有指定就不要做。\n",
    "    3.异常值处理之前需要将缺失值处理干净，保证数据没有缺失值不然会报错"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b9d6c44",
   "metadata": {},
   "source": [
    "2.1 异常值检测-3σ原则"
   ]
  },
  {
   "cell_type": "raw",
   "id": "9df37130",
   "metadata": {},
   "source": [
    "3σ原理公式：|x-μ|>3σ：也就是其值与均值的差值的绝对值大于3倍标准差的值就是异常值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7c4d5401",
   "metadata": {},
   "outputs": [],
   "source": [
    "mean = df['Age'].mean()  # 均值\n",
    "std = df['Age'].std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a2360a49",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23.0\n",
      "34.0\n",
      "34.0\n",
      "28.0\n",
      "21.0\n",
      "33.0\n",
      "37.0\n",
      "28.0\n",
      "21.0\n",
      "38.0\n",
      "47.0\n",
      "14.5\n",
      "22.0\n",
      "20.0\n",
      "17.0\n",
      "21.0\n",
      "70.5\n",
      "29.0\n",
      "24.0\n",
      "2.0\n",
      "21.0\n",
      "32.5\n",
      "32.5\n",
      "54.0\n",
      "12.0\n",
      "24.0\n",
      "45.0\n",
      "33.0\n",
      "20.0\n",
      "47.0\n",
      "29.0\n",
      "25.0\n",
      "23.0\n",
      "19.0\n",
      "37.0\n",
      "16.0\n",
      "24.0\n",
      "22.0\n",
      "24.0\n",
      "19.0\n",
      "18.0\n",
      "19.0\n",
      "27.0\n",
      "9.0\n",
      "36.5\n",
      "42.0\n",
      "51.0\n",
      "22.0\n",
      "55.5\n",
      "40.5\n",
      "51.0\n",
      "16.0\n",
      "30.0\n",
      "44.0\n",
      "40.0\n",
      "26.0\n",
      "17.0\n",
      "1.0\n",
      "9.0\n",
      "45.0\n",
      "28.0\n",
      "61.0\n",
      "4.0\n",
      "1.0\n",
      "21.0\n",
      "56.0\n",
      "18.0\n",
      "50.0\n",
      "30.0\n",
      "36.0\n",
      "9.0\n",
      "1.0\n",
      "4.0\n",
      "45.0\n",
      "40.0\n",
      "36.0\n",
      "32.0\n",
      "19.0\n",
      "19.0\n",
      "3.0\n",
      "44.0\n",
      "58.0\n",
      "42.0\n",
      "24.0\n",
      "28.0\n",
      "34.0\n",
      "45.5\n",
      "18.0\n",
      "2.0\n",
      "32.0\n",
      "26.0\n",
      "16.0\n",
      "40.0\n",
      "24.0\n",
      "35.0\n",
      "22.0\n",
      "30.0\n",
      "31.0\n",
      "27.0\n",
      "42.0\n",
      "32.0\n",
      "30.0\n",
      "16.0\n",
      "27.0\n",
      "51.0\n",
      "38.0\n",
      "22.0\n",
      "19.0\n",
      "20.5\n",
      "18.0\n",
      "35.0\n",
      "29.0\n",
      "59.0\n",
      "5.0\n",
      "24.0\n",
      "44.0\n",
      "8.0\n",
      "19.0\n",
      "33.0\n",
      "29.0\n",
      "22.0\n",
      "30.0\n",
      "44.0\n",
      "25.0\n",
      "24.0\n",
      "37.0\n",
      "54.0\n",
      "29.0\n",
      "62.0\n",
      "30.0\n",
      "41.0\n",
      "29.0\n",
      "30.0\n",
      "35.0\n",
      "50.0\n",
      "3.0\n",
      "52.0\n",
      "40.0\n",
      "36.0\n",
      "16.0\n",
      "25.0\n",
      "58.0\n",
      "35.0\n",
      "25.0\n",
      "41.0\n",
      "37.0\n",
      "63.0\n",
      "45.0\n",
      "7.0\n",
      "35.0\n",
      "65.0\n",
      "28.0\n",
      "16.0\n",
      "19.0\n",
      "33.0\n",
      "30.0\n",
      "22.0\n",
      "42.0\n",
      "22.0\n",
      "26.0\n",
      "19.0\n",
      "36.0\n",
      "24.0\n",
      "24.0\n",
      "23.5\n",
      "2.0\n",
      "50.0\n",
      "19.0\n",
      "0.92\n",
      "17.0\n",
      "30.0\n",
      "30.0\n",
      "24.0\n",
      "18.0\n",
      "26.0\n",
      "28.0\n",
      "43.0\n",
      "26.0\n",
      "24.0\n",
      "54.0\n",
      "31.0\n",
      "40.0\n",
      "22.0\n",
      "27.0\n",
      "30.0\n",
      "22.0\n",
      "36.0\n",
      "61.0\n",
      "36.0\n",
      "31.0\n",
      "16.0\n",
      "45.5\n",
      "38.0\n",
      "16.0\n",
      "29.0\n",
      "41.0\n",
      "45.0\n",
      "45.0\n",
      "2.0\n",
      "24.0\n",
      "28.0\n",
      "25.0\n",
      "36.0\n",
      "24.0\n",
      "40.0\n",
      "3.0\n",
      "42.0\n",
      "23.0\n",
      "15.0\n",
      "25.0\n",
      "28.0\n",
      "22.0\n",
      "38.0\n",
      "40.0\n",
      "29.0\n",
      "45.0\n",
      "35.0\n",
      "30.0\n",
      "60.0\n",
      "24.0\n",
      "25.0\n",
      "18.0\n",
      "19.0\n",
      "22.0\n",
      "3.0\n",
      "22.0\n",
      "27.0\n",
      "20.0\n",
      "19.0\n",
      "42.0\n",
      "1.0\n",
      "32.0\n",
      "35.0\n",
      "18.0\n",
      "1.0\n",
      "36.0\n",
      "17.0\n",
      "36.0\n",
      "21.0\n",
      "28.0\n",
      "23.0\n",
      "24.0\n",
      "22.0\n",
      "31.0\n",
      "46.0\n",
      "23.0\n",
      "28.0\n",
      "39.0\n",
      "26.0\n",
      "21.0\n",
      "28.0\n",
      "20.0\n",
      "34.0\n",
      "51.0\n",
      "3.0\n",
      "21.0\n",
      "33.0\n",
      "44.0\n",
      "34.0\n",
      "18.0\n",
      "30.0\n",
      "10.0\n",
      "21.0\n",
      "29.0\n",
      "28.0\n",
      "18.0\n",
      "28.0\n",
      "19.0\n",
      "32.0\n",
      "28.0\n",
      "42.0\n",
      "17.0\n",
      "50.0\n",
      "14.0\n",
      "21.0\n",
      "24.0\n",
      "64.0\n",
      "31.0\n",
      "45.0\n",
      "20.0\n",
      "25.0\n",
      "28.0\n",
      "4.0\n",
      "13.0\n",
      "34.0\n",
      "5.0\n",
      "52.0\n",
      "36.0\n",
      "30.0\n",
      "49.0\n",
      "29.0\n",
      "65.0\n",
      "50.0\n",
      "48.0\n",
      "34.0\n",
      "47.0\n",
      "48.0\n",
      "38.0\n",
      "56.0\n",
      "0.75\n",
      "38.0\n",
      "33.0\n",
      "23.0\n",
      "22.0\n",
      "34.0\n",
      "29.0\n",
      "22.0\n",
      "2.0\n",
      "9.0\n",
      "50.0\n",
      "63.0\n",
      "25.0\n",
      "35.0\n",
      "58.0\n",
      "30.0\n",
      "9.0\n",
      "21.0\n",
      "55.0\n",
      "71.0\n",
      "21.0\n",
      "54.0\n",
      "25.0\n",
      "24.0\n",
      "17.0\n",
      "21.0\n",
      "37.0\n",
      "16.0\n",
      "18.0\n",
      "33.0\n",
      "28.0\n",
      "26.0\n",
      "29.0\n",
      "36.0\n",
      "54.0\n",
      "24.0\n",
      "47.0\n",
      "34.0\n",
      "36.0\n",
      "32.0\n",
      "30.0\n",
      "22.0\n",
      "44.0\n",
      "40.5\n",
      "50.0\n",
      "39.0\n",
      "23.0\n",
      "2.0\n",
      "17.0\n",
      "30.0\n",
      "7.0\n",
      "45.0\n",
      "30.0\n",
      "22.0\n",
      "36.0\n",
      "9.0\n",
      "11.0\n",
      "32.0\n",
      "50.0\n",
      "64.0\n",
      "19.0\n",
      "33.0\n",
      "8.0\n",
      "17.0\n",
      "27.0\n",
      "22.0\n",
      "22.0\n",
      "62.0\n",
      "48.0\n",
      "39.0\n",
      "36.0\n",
      "40.0\n",
      "28.0\n",
      "24.0\n",
      "19.0\n",
      "29.0\n",
      "32.0\n",
      "62.0\n",
      "53.0\n",
      "36.0\n",
      "16.0\n",
      "19.0\n",
      "34.0\n",
      "39.0\n",
      "32.0\n",
      "25.0\n",
      "39.0\n",
      "54.0\n",
      "36.0\n",
      "18.0\n",
      "47.0\n",
      "60.0\n",
      "22.0\n",
      "35.0\n",
      "52.0\n",
      "47.0\n",
      "37.0\n",
      "36.0\n",
      "49.0\n",
      "49.0\n",
      "24.0\n",
      "44.0\n",
      "35.0\n",
      "36.0\n",
      "30.0\n",
      "27.0\n",
      "22.0\n",
      "40.0\n",
      "39.0\n",
      "35.0\n",
      "24.0\n",
      "34.0\n",
      "26.0\n",
      "4.0\n",
      "26.0\n",
      "27.0\n",
      "42.0\n",
      "20.0\n",
      "21.0\n",
      "21.0\n",
      "61.0\n",
      "57.0\n",
      "21.0\n",
      "26.0\n",
      "80.0\n",
      "51.0\n",
      "32.0\n",
      "9.0\n",
      "28.0\n",
      "32.0\n",
      "31.0\n",
      "41.0\n",
      "20.0\n",
      "24.0\n",
      "2.0\n",
      "0.75\n",
      "48.0\n",
      "19.0\n",
      "56.0\n",
      "23.0\n",
      "18.0\n",
      "21.0\n",
      "18.0\n",
      "24.0\n",
      "32.0\n",
      "23.0\n",
      "58.0\n",
      "50.0\n",
      "40.0\n",
      "47.0\n",
      "36.0\n",
      "20.0\n",
      "32.0\n",
      "25.0\n",
      "43.0\n",
      "40.0\n",
      "31.0\n",
      "70.0\n",
      "31.0\n",
      "18.0\n",
      "24.5\n",
      "18.0\n",
      "43.0\n",
      "36.0\n",
      "27.0\n",
      "20.0\n",
      "14.0\n",
      "60.0\n",
      "25.0\n",
      "14.0\n",
      "19.0\n",
      "18.0\n",
      "15.0\n",
      "31.0\n",
      "4.0\n",
      "25.0\n",
      "60.0\n",
      "52.0\n",
      "44.0\n",
      "49.0\n",
      "42.0\n",
      "18.0\n",
      "35.0\n",
      "18.0\n",
      "25.0\n",
      "26.0\n",
      "39.0\n",
      "45.0\n",
      "42.0\n",
      "22.0\n",
      "24.0\n",
      "48.0\n",
      "29.0\n",
      "52.0\n",
      "19.0\n",
      "38.0\n",
      "27.0\n",
      "33.0\n",
      "6.0\n",
      "17.0\n",
      "34.0\n",
      "50.0\n",
      "27.0\n",
      "20.0\n",
      "30.0\n",
      "25.0\n",
      "25.0\n",
      "29.0\n",
      "11.0\n",
      "23.0\n",
      "23.0\n",
      "28.5\n",
      "48.0\n",
      "35.0\n",
      "36.0\n",
      "21.0\n",
      "24.0\n",
      "31.0\n",
      "70.0\n",
      "16.0\n",
      "30.0\n",
      "19.0\n",
      "31.0\n",
      "4.0\n",
      "6.0\n",
      "33.0\n",
      "23.0\n",
      "48.0\n",
      "0.67\n",
      "28.0\n",
      "18.0\n",
      "34.0\n",
      "33.0\n",
      "41.0\n",
      "20.0\n",
      "36.0\n",
      "16.0\n",
      "51.0\n",
      "30.5\n",
      "32.0\n",
      "24.0\n",
      "48.0\n",
      "57.0\n",
      "54.0\n",
      "18.0\n",
      "5.0\n",
      "43.0\n",
      "13.0\n",
      "17.0\n",
      "29.0\n",
      "25.0\n",
      "25.0\n",
      "18.0\n",
      "8.0\n",
      "1.0\n",
      "46.0\n",
      "16.0\n",
      "25.0\n",
      "39.0\n",
      "49.0\n",
      "31.0\n",
      "30.0\n",
      "30.0\n",
      "34.0\n",
      "31.0\n",
      "11.0\n",
      "0.42\n",
      "27.0\n",
      "31.0\n",
      "39.0\n",
      "18.0\n",
      "39.0\n",
      "33.0\n",
      "26.0\n",
      "39.0\n",
      "35.0\n",
      "6.0\n",
      "30.5\n",
      "23.0\n",
      "31.0\n",
      "43.0\n",
      "10.0\n",
      "52.0\n",
      "27.0\n",
      "38.0\n",
      "27.0\n",
      "2.0\n",
      "1.0\n",
      "15.0\n",
      "0.83\n",
      "23.0\n",
      "18.0\n",
      "39.0\n",
      "21.0\n",
      "32.0\n",
      "20.0\n",
      "16.0\n",
      "30.0\n",
      "34.5\n",
      "17.0\n",
      "42.0\n",
      "35.0\n",
      "28.0\n",
      "4.0\n",
      "74.0\n",
      "9.0\n",
      "16.0\n",
      "44.0\n",
      "18.0\n",
      "45.0\n",
      "51.0\n",
      "24.0\n",
      "41.0\n",
      "21.0\n",
      "48.0\n",
      "24.0\n",
      "42.0\n",
      "27.0\n",
      "31.0\n",
      "4.0\n",
      "26.0\n",
      "47.0\n",
      "33.0\n",
      "47.0\n",
      "28.0\n",
      "15.0\n",
      "20.0\n",
      "19.0\n",
      "56.0\n",
      "25.0\n",
      "33.0\n",
      "22.0\n",
      "28.0\n",
      "25.0\n",
      "39.0\n",
      "27.0\n",
      "19.0\n",
      "26.0\n",
      "32.0\n"
     ]
    }
   ],
   "source": [
    "for x in df['Age'].index:\n",
    "    if np.abs(x-mean)>3*std:\n",
    "        print(df['Age'][x])\n",
    "#         df.drop(axis=0,index=x,inplace=True)  # 删除\n",
    "#         df['Age'][x] = df['Age'][x].replace(df['Age'][x],df['Age'].mean())  # 替换"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb33e927",
   "metadata": {},
   "source": [
    "2.1 异常值检测-箱线图"
   ]
  },
  {
   "cell_type": "raw",
   "id": "ab014c78",
   "metadata": {},
   "source": [
    "箱线图原理公式：Q1+1.5*IQR<x<Q3-1.5*IQR:也就是其值大于上边界(Q1+1.5*IQR)小于下边界(Q3-1.5*IQR)的值就被定义为异常值。IQR=Q1-Q3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ffbdefd",
   "metadata": {},
   "source": [
    "读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6219fea0",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>PassengerId</th>\n",
       "      <th>Survived</th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Name</th>\n",
       "      <th>Sex</th>\n",
       "      <th>Age</th>\n",
       "      <th>SibSp</th>\n",
       "      <th>Parch</th>\n",
       "      <th>Ticket</th>\n",
       "      <th>Fare</th>\n",
       "      <th>Embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Braund, Mr. Owen Harris</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>A/5 21171</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>PC 17599</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>Heikkinen, Miss. Laina</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>STON/O2. 3101282</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>113803</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Allen, Mr. William Henry</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>373450</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0  PassengerId  Survived  Pclass  \\\n",
       "0           0            1         0       3   \n",
       "1           1            2         1       1   \n",
       "2           2            3         1       3   \n",
       "3           3            4         1       1   \n",
       "4           4            5         0       3   \n",
       "\n",
       "                                                Name     Sex   Age  SibSp  \\\n",
       "0                            Braund, Mr. Owen Harris    male  22.0      1   \n",
       "1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1   \n",
       "2                             Heikkinen, Miss. Laina  female  26.0      0   \n",
       "3       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1   \n",
       "4                           Allen, Mr. William Henry    male  35.0      0   \n",
       "\n",
       "   Parch            Ticket     Fare Embarked  \n",
       "0      0         A/5 21171   7.2500        S  \n",
       "1      0          PC 17599  71.2833        C  \n",
       "2      0  STON/O2. 3101282   7.9250        S  \n",
       "3      0            113803  53.1000        S  \n",
       "4      0            373450   8.0500        S  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('./titanic_trains_nonull.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4e059565",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy88F64QAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAjYklEQVR4nO3df1Rb9f3H8VdK1wgKOGtNyKQlk3R0gk7Qw0rHF9iEnep6xrBzE93pzs526qjbsE6Udj+oZyYTFesZa2d7PB1bx3HneLDb6TYt244UD3VDWJ2tVavSyiYR9bAktgincL9/dGRG8Edo+ITA83HOPTP33oQ3/yzPfrjJtVmWZQkAAMCQBfEeAAAAzC/EBwAAMIr4AAAARhEfAADAKOIDAAAYRXwAAACjiA8AAGAU8QEAAIxaGO8B3m18fFyvvvqqUlNTZbPZ4j0OAAD4ECzLUigUksvl0oIF77+2Mevi49VXX1VmZma8xwAAANPQ39+vCy+88H3PmXXxkZqaKun08GlpaXGeBgAAfBjBYFCZmZnh9/H3M+viY+JPLWlpacQHAAAJ5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m6u/vjHP2rZsmUz8eMAAEACmZHv+TgTfM8HAACJJ5r3b+7tAgAAjCI+AACAUcQHAAAwivgAAABGER8AAMAo4gMAABhFfAAAAKNm5EvGzsTE144Eg8E4TwIAAD6sifftD/P1YbMuPkKhkCQpMzMzzpMAAIBohUIhpaenv+85s+4bTsfHx/Xqq68qNTVVNpst3uMAiKFgMKjMzEz19/fzDcbAHGNZlkKhkFwulxYseP+rOmZdfACYu7h9AgCJC04BAIBhxAcAADCK+ABgjN1u149//GPZ7fZ4jwIgjrjmAwAAGMXKBwAAMIr4AAAARhEfAADAKOIDAAAYRXwAMGL//v1as2aNXC6XbDab9uzZE++RAMQJ8QHAiBMnTujSSy9Vc3NzvEcBEGez7sZyAOam1atXa/Xq1fEeA8AswMoHAAAwivgAAABGER8AAMAo4gMAABhFfAAAAKP4tAsAI9566y29+OKL4cd9fX06ePCgzjvvPC1dujSOkwEwjbvaAjDi8ccfV1lZ2aT969at0y9/+UvzAwGIG+IDAAAYxTUfAADAKOIDAAAYRXwAAACjiA8AAGAU8QEAAIwiPgAAgFHEBwAAMIr4AAAARhEfAADAKOIDAAAYRXwAAACjiA8AAGDU/wNH+2uCQBb+sgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.boxplot(df['Age'])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "04eda44e",
   "metadata": {},
   "outputs": [],
   "source": [
    "sfw = df['Age'].describe() # 四分位数\n",
    "Q1 = sfw['75%'] #上四分位数\n",
    "Q3 = sfw['25%'] # 下四分位数\n",
    "IQR = Q1-Q3 # IQR\n",
    "up = Q1+1.5*IQR  # 上边界\n",
    "down = Q3-1.5*IQR # 下边界"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6b98591b",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "66.0\n",
      "71.0\n",
      "70.5\n",
      "71.0\n",
      "80.0\n",
      "70.0\n",
      "70.0\n",
      "74.0\n"
     ]
    }
   ],
   "source": [
    "for x in df['Age'].index:\n",
    "    if df['Age'][x]>up or df['Age'][x]<down:\n",
    "        print(df['Age'][x])\n",
    "#         df.drop(axis=0,index=x,inplace=True)  # 删除\n",
    "#         df['Age'][x] = df['Age'][x].replace(df['Age'][x],df['Age'].mean()) # 替换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9613139e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
